<?php

include '../../libraries/dbconfig.php';
session_start();
date_default_timezone_set('Asia/Calcutta');
$date1 = date("Y-m-d H:i:s");

if ($_POST['chkDel']) {
    $chk = $_POST['chkDel'];
    //print_r($chk);
    if ($_SESSION['display']) {
        $display = $_SESSION['display'];
        for ($i = 0; $i <= count($chk); $i++) {
            unset($display[$chk[$i]]);
        }
    }
}

Sort($display);
$_SESSION['display'] = $display;

$result = $display;
$dsc = mysql_query("select * from options");
$dsc_data = mysql_fetch_array($dsc);
for ($row = 0; $row < count($result); $row++) {
    // echo "  Name :" . $result[$row]['productid'] . " <br> qty :" . $result[$row]['qty'];
    // echo "<br />";

    $product_id = $result[$row]['productid'];
    $discount = $result[$row]['discount'];

    $products = mysql_query("select * from products where productid = $product_id");
    $products_data = mysql_fetch_array($products);

    if ($dsc_data['discount_type'] == "amount") {
        $total = ($products_data['price'] - $discount) * $result[$row]['qty'];
        $dup_total = $total_rate + $total;
        $total_rate = $dup_total;
        $vat_tax = ($total / 100) * 14.5;
        $amount = $total + $vat_tax;
        $dup_vat = $total_vat + $vat_tax;
        $total_vat = $dup_vat;
        $bill_total = $total_rate + $total_vat;
        $dup_discount = $total_discount + ($discount * $result[$row]['qty']);
        $total_discount = $dup_discount;
    } else {
        $total = ($products_data['price'] - ((($products_data['price']) / 100) * $discount)) * $result[$row]['qty'];
        $dup_total = $total_rate + $total;
        $total_rate = $dup_total;
        $vat_tax = ($total / 100) * 14.5;
        $amount = $total + $vat_tax;
        $dup_vat = $total_vat + $vat_tax;
        $total_vat = $dup_vat;
        $bill_total = $total_rate + $total_vat;
        $dup_discount = $total_discount + (((($products_data['price']) / 100) * $discount) * $result[$row]['qty']);
        $total_discount = $dup_discount;
    }
}













$total = array();
$total["date"] = $date1;
$total["total_rate"] = $total_rate;
$total["total_discount"] = $total_discount;
$total["total_vat"] = $total_vat;
$total["bill_total"] = $bill_total;
$back = array($display, $total);

echo json_encode($back);
?>
   